<?php
/**
 * 数据安装验证操作类
 * 此模块仅可在站长后台数据校验界面调用！
 */

namespace ins;

use config;

/**
 * Class install
 * @package ins
 * sql数据验证校准类，便于后续升级维护
 * 此处未固有数据，跟随版本变化
 * 核心部分已转移到软件商店内！
 */
class install
{
    var $arr;

    /**
     * @param string $type html 返回 json 返回
     * 此处为conf默认配置
     */

    public function config_verify($type = 'html')
    {
        global $DB;
        $data = [
            'template' => 'cloud|PC端模板',
            'template_m' => 'AppStore|手机端模板',
            'cdnpublic' => '4|CDN节点',
            'cdnserver' => '2|动态加速节点',
            'sitename' => '小储云商城|商城名称',
            'kfqq' => '123456|客服QQ',
            'Communication' => '加群链接|官方群链接',
            'award' => '1000|邀请奖励货币数量',
            'keywords' => '小储云商城,名片赞,免费名片赞,刷赞,免费,代刷网|网站关键词',
            'description' => '小储云商城是一个线上购物网站，你应该可以在里面找到你需要的商品哦！|网站描述语句',
            'logo' => 'assets/img/logo.png|网站logo图地址',
            'Signin' => '100|签到赠送货币数量',
            'currency' => '积分|积分名称',
            'notice_top' => '请手动编辑公告|首页公告',
            'notice_check' => '请手动编辑公告|首页查单公告',
            'notice_bottom' => '请手动编辑公告|全局底部公告',
            'notice_user' => '请手动编辑公告|分站后台公告',
            'statistics' => '|IP统计代码',
            'appurl' => '|APP下载地址',
            'navigation' => '百度一下,跳转链接|前台导航链接',
            'pay_qqapy' => '-1|QQ支付接口,-1关闭,1易支付,2码支付',
            'pay_wxpay' => '-1|微信支付接口,-1关闭,1易支付,2码支付',
            'pay_alipay' => '-1|支付宝支付接口,-1关闭,1易支付,2码支付',
            'pay_url' => '|易支付接口域名',
            'pay_partner' => '|易支付商户ID',
            'pay_key' => '|易支付商户token',
            'getinreturn' => '5|每日单一用户可用积分兑换商品的次数(包含免费商品)',
            'getinreturn_all' => '100|每日整个网站可用积分兑换商品的次数(包含免费商品)',
            'cpay_id' => '|码支付ID',
            'cpay_key' => '|码支付密钥',
            'prevent_url' => '|防洪接口',
            'prevent_type' => 'qq|防洪生成类型qq/vx',
            'prevent_dwzapi' => '2|网址缩短类型',
            'prevent_format' => 'json|防洪返回类型[json|txt|qrcode]',
            'prevent_switch' => '-1|-1关闭,1开启',
            'background' => '4|背景图片，1必应每日，2必应随机，3二次元随机',
            'Interface' => '1|API接口列表',
            'secret' => md5(rand(10000, 1000000) . time()) . '|对接密钥',
            'sms_switch_user' => '-1|-1关闭，1开启，用户后台短信开关',
            'sms_switch_order' => '-1|-1关闭，1开启，订单购买短信开关',
            'alipay_public_key' => '|当面付公钥',
            'merchant_private_key' => '|当面付私钥',
            'alipay_fpay_id' => '|支付宝应用ID',
            'banner' => '/assets/cool/picture/1571065392993013.png*/user|首页banner图',
            'weix_notice' => '-1|公众号订单提醒',
            'alipay_name' => '|当面付商品名称自定义！',
            'userdeposit' => '1|提现开关',
            'userleague' => '1|加盟开关',
            'userleaguegrade' => '2|加盟等级限制',
            'userdepositgrade' => '2|提现等级限制',
            'usergradenotice' => '2|加盟用户多少级可以自定义公告，客服？',
            'usergradeprofit' => '3|加盟店多少级可以自定义利润？,只能多不能少',
            'usergradegoodsstate' => '4|加盟店多少级可以自定义商品状态？',
            'userdefaultgrade' => '1|用户注册默认等级',
            'usersmsbinding' => '3|每日用户换绑短信发送次数',
            'usersmslogin' => '3|每日用户登陆短信发送次数',
            'userdepositservice' => '5|用户提现手续费',
            'usergradecost' => '-1|用户升级费用是否奖励给他的上级？如果有的话',
            'userdepositmin' => '10|用户最少提现多少钱？',
            'userdeposittype' => '1,1,1|用户提现支持方式',
            'usergradetem' => '4|用户多少级可以自定义模板？',
            'userdomain' => href() . '|加盟店铺可选域名主体',
            'userdomainretain' => 'www,m|主站保留前缀',
            'userdomainsetmoney' => '5|域名修改价格',
            'userdomaintype' => '1|1=泛解析模式,2=cookie绑定模式',
            'blacklist' => '|禁止下单信息',
            'SecurityCenter' => '1|安全中心开关',
            'share_url' => '我钱不够买这个东西，能够帮我买一下嘛~，这是付款订单,谢谢啦 [url]|商品代付款分享语句',
            'title' => '|网站副标题',
            'share_image' => '1|分享海报获取方式,1=本地获取,2=云端获取',
            'compression' => '0.5|图片上传压缩比例',
            'CartPaySet' => '1,2,3,4,5|购物车支持付款方式',
            'CartNotice' => '付款后订单未到账可联系客服处理！|购物车公告内容',
            'OredeQueue' => '1|订单队列模式,1不使用,2使用',
            'PopupNotice' => '|首页弹窗公告',
            'ForcedLanding' => '1|1不强制用户登陆,2强制用户必须登陆！',
            'CartState' => '1|购物车开关',
            'SubmitState' => '2|对接货源下单失败后的状态设置',
            'OrderAstrict' => '120|相同下单信息的商品提交间隔限制,秒',
            'TicketsClass' => '订单问题,充值问题,网站BUG,优化建议|工单类型,可自定义',
            'prevent_return' => 'ae_url|防红自定义返回字段名称',
            'prevent_field' => '[url]|防洪自定义提交字段名称',
            'Homecaching' => '60|首页数据缓存周期',
            'SalesSum' => '0|保底销量',
            'WeixQqValidation' => '2|验证是否是在QQ内打开,是的话拦截！',
            'CloseWebsite' => '|关闭网站的原因,留空不关闭！',
            'YzfSign' => '|云智服SIGN',
            'SupervisorySwitch' => '1|监控总开关',
            'SupervisoryError' => '2|监控到对接商品下架后操作',
            'SupervisorySuccess' => '2|监控商品上架后操作',
            'SupervisoryCycle' => '60|静默监控间隔时间',
            'SupervisoryMsg' => '当前商品有新的调整|监控商品价格状态有变化时提示信息！',
            'GoodsRecommendation' => '1|开启或关闭APP模板商品推荐',
            'Protect' => '|目录保护,留空不保护！',
            'HomePageDisplay' => '1|1=固定排序,2=随机排序',
            'AccountPasswordLogin' => '2|1=开启,2=关闭',
        ];
        $config = new config();
        if ($DB->count("SELECT count(*) FROM `sky_config` ;") < count($data)) {
            foreach ($data as $k => $v) {
                $sq = explode('|', $v);
                @$DB->query("INSERT INTO `sky_config` (`K`, `V`, `C`) VALUES ('$k', '{$sq[0]}', '{$sq[1]}')");
            }
            if ($type == 'html') {
                $config->unset_cache();
                show_msg('恭喜', '已经成功帮您升级校准公共数据,请刷新界面！', 1, false, false);
            } else {
                $config->unset_cache();
                dies(1, '已经成功帮您升级校准公共数据!');
            }
        }
    }

    /**
     * @return array
     * 输出需要验证的数据库数组
     */
    public function sql_arr()
    {
        /**
         * 数组结构说明：
         * （$arr[0] 类型）
         * （$arr[1] 长度）
         * （$arr[2] 小数点）
         * （$arr[3] 不是null）
         * （$arr[4] 是否递增）
         * （$arr[5] 默认填写）
         * 结构遵循 navicat premium 习惯
         */
        $array = [
            'sky_buylog' => [
                'id' => 'int/11/0/1/1/NULL',
                'gid' => 'int/11/0/0/0/NULL',
                'uid' => 'int/11/0/0/0/NULL',
                'num' => 'int/11/0/0/0/1',
                'ip' => 'varchar/255/0/0/0/NULL',
                'date' => 'datetime/0/0/0/0/NULL',
            ],
            'sky_class' => [
                'cid' => 'int/11/0/1/1/NULL',
                'sort' => 'int/11/0/0/0/NULL',
                'name' => 'varchar/255/0/0/0/NULL',
                'image' => 'text/0/0/0/0/NULL',
                'content' => 'text/0/0/0/0/NULL',
                'state' => 'int/11/0/0/0/1',
                'date' => 'datetime/0/0/0/0/NULL'
            ],
            'sky_goods' => [
                'gid' => 'int/11/0/1/1/NULL',
                'cid' => 'int/11/0/0/0/1',
                'sort' => 'int/11/0/0/0/NULL',
                'name' => 'varchar/255/0/0/0/NULL',
                'image' => 'varchar/255/0/0/0/NULL',
                'picture' => 'text/0/0/0/0/NULL',
                'money' => 'decimal/24/8/0/0/NULL',
                'profits' => 'decimal/24/0/0/0/100',
                'custom' => 'text/0/0/0/0/NULL',
                'min' => 'int/255/0/0/0/1',
                'max' => 'int/255/0/0/0/NULL',
                'freight' => 'varchar/255/0/0/0/-1',
                'method' => 'varchar/255/0/0/0/[1,2,3,4,5,6,7]',
                'value' => 'text/0/0/0/0/NULL',
                'quota' => 'varchar/255/0/0/0/NULL',
                'quantity' => 'varchar/255/0/0/0/NULL',
                'docs' => 'text/0/0/0/0/NULL',
                'alert' => 'text/0/0/0/0/NULL',
                'sqid' => 'int/11/0/0/0/NULL',
                'state' => 'int/11/0/0/0/1',
                'curl' => 'text/0/0/0/0/NULL',
                'post_data' => 'text/0/0/0/0/NULL',
                'goods_id' => 'int/11/0/0/0/NULL',
                'goods_type' => 'int/11/0/0/0/NULL',
                'goods_url' => 'text/0/0/0/0/NULL',
                'goods_mainKey' => 'text/0/0/0/0/NULL',
                'note' => 'text/0/0/0/0/NULL',
                'submit_the_field' => 'varchar/255/0/0/0/NULL',
                'date' => 'datetime/0/0/0/0/NULL'
            ],
            'sky_invite' => [
                'id' => 'int/11/0/1/1/NULL',
                'uid' => 'int/11/0/0/0/NULL',
                'invitee' => 'int/11/0/0/0/NULL',
                'award' => 'decimal/11/0/0/0/NULL',
                'ip' => 'varchar/255/0/0/0/NULL',
                'draw_time' => 'datetime/0/0/0/0/NULL',
                'creation_time' => 'datetime/0/0/0/0/NULL'
            ],
            'sky_journal' => [
                'id' => 'int/11/0/1/1/NULL',
                'ip' => 'varchar/255/0/0/0/NULL',
                'uid' => 'int/11/0/0/0/NULL',
                'count' => 'decimal/24/8/0/0/NULL',
                'name' => 'varchar/255/0/0/0/NULL',
                'content' => 'text/0/0/0/0/NULL',
                'date' => 'datetime/0/0/0/0/NULL'
            ],
            'sky_login' => [
                'id' => 'int/11/0/1/1/NULL',
                'token' => 'varchar/255/0/0/0/NULL',
                'ip' => 'varchar/255/0/0/0/NULL',
                'state' => 'int/11/0/0/0/3',
                'finish_time' => 'datetime/0/0/0/0/NULL',
                'date_created' => 'datetime/0/0/0/0/NULL',
            ],
            'sky_notice' => [
                'id' => 'int/11/0/1/1/NULL',
                'title' => 'varchar/255/0/0/0/NULL',
                'content' => 'text/0/0/0/0/NULL',
                'browse' => 'text/0/0/0/0/NULL',
                'date' => 'datetime/0/0/0/0/NULL'
            ],
            'sky_order' => [
                'id' => 'int/11/0/1/1/NULL',
                'order' => 'varchar/255/0/0/0/NULL',
                'trade_no' => 'varchar/255/0/0/0/NULL',
                'uid' => 'int/11/0/0/0/NULL',
                'ip' => 'varchar/255/0/0/0/NULL',
                'input' => 'varchar/255/0/0/0/NULL',
                'state' => 'int/11/0/0/0/NULL',
                'num' => 'int/11/0/0/0/1',
                'return' => 'text/0/0/0/0/NULL',
                'gid' => 'int/11/0/0/0/NULL',
                'order_id' => 'text/0/0/0/0/NULL',
                'money' => 'decimal/24/8/0/0/NULL',
                'payment' => 'varchar/255/0/0/0/NULL',
                'take' => 'int/1/0/0/0/1',
                'price' => 'decimal/24/8/0/0/NULL',
                'user_rmb' => 'decimal/24/8/0/0/NULL',
                'remark' => 'text/0/0/0/0/NULL',
                'finishtime' => 'timestamp/0/0/0/0/NULL',
                'addtitm' => 'datetime/0/0/0/0/NULL'
            ],
            'sky_pay' => [
                'id' => 'int/11/0/1/1/NULL',
                'order' => 'varchar/255/0/0/0/NULL',
                'trade_no' => 'varchar/255/0/0/0/NULL',
                'type' => 'varchar/11/0/0/0/NULL',
                'uid' => 'int/11/0/0/0/NULL',
                'gid' => 'int/11/0/0/0/NULL',
                'name' => 'varchar/255/0/0/0/NULL',
                'money' => 'decimal/24/8/0/0/NULL',
                'ip' => 'varchar/255/0/0/0/NULL',
                'input' => 'text/0/0/0/0/NULL',
                'num' => 'int/11/0/0/0/1',
                'state' => 'int/11/0/0/0/2',
                'verify' => 'varchar/255/0/0/0/-1',
                'endtime' => 'datetime/0/0/0/0/NULL',
                'addtime' => 'datetime/0/0/0/0/NULL',
            ],
            'sky_shequ' => [
                'id' => 'int/11/0/1/1/NULL',
                'url' => 'varchar/255/0/0/0/NULL',
                'type' => 'int/11/0/0/0/1',
                'username' => 'varchar/255/0/0/0/NULL',
                'password' => 'varchar/255/0/0/0/NULL',
                'secret' => 'varchar/255/0/0/0/NULL',
                'pattern' => 'varchar/255/0/0/0/1',
                'date' => 'datetime/0/0/0/0/NULL',
            ],
            'sky_token' => [
                'kid' => 'int/11/0/1/1/NULL',
                'uid' => 'int/11/0/0/0/1',
                'gid' => 'int/11/0/0/0/NULL',
                'code' => 'varchar/255/0/0/0/NULL',
                'token' => 'varchar/255/0/0/0/NULL',
                'ip' => 'varchar/255/0/0/0/NULL',
                'order' => 'varchar/255/0/0/0/NULL',
                'endtime' => 'datetime/0/0/0/0/NULL',
                'addtime' => 'datetime/0/0/0/0/NULL',
            ],
            'sky_user' => [
                'id' => 'int/11/0/1/1/NULL',
                'user_idu' => 'varchar/255/0/0/0/NULL',
                'username' => 'text/0/0/0/0/NULL',
                'password' => 'text/0/0/0/0/NULL',
                'token' => 'varchar/255/0/0/0/NULL',
                'ip_white_list' => 'text/0/0/0/0/NULL',
                'superior' => 'int/11/0/0/0/NULL',
                'currency' => 'decimal/24/0/0/0/0',
                'ip' => 'varchar/255/0/0/0/NULL',
                'money' => 'decimal/24/8/0/0/0.00000000',
                'grade' => 'int/255/0/0/0/1',
                'domain' => 'varchar/255/0/0/0/NULL',
                'configuration' => 'text/0/0/0/0/NULL',
                'image' => 'varchar/255/0/0/0/NULL',
                'name' => 'varchar/255/0/0/0/NULL',
                'qq' => 'varchar/255/0/0/0/NULL',
                'mobile' => 'varchar/255/0/0/0/NULL',
                'state' => 'int/11/0/0/0/NULL',
                'recent_time' => 'timestamp/0/0/0/0/NULL',
                'found_date' => 'datetime/0/0/0/0/NULL',
            ],
            'sky_price' => [
                'mid' => 'int/12/0/1/1/NULL',
                'sort' => 'int/12/0/0/0/NULL',
                'name' => 'varchar/255/0/0/0/NULL',
                'content' => 'text/0/0/0/0/NULL',
                'priceis' => 'text/0/0/0/0/NULL',
                'pointsis' => 'text/0/0/0/0/NULL',
                'state' => 'int/12/0/0/0/1',
                'money' => 'decimal/12/2/0/0/0',
                'addtime' => 'datetime/0/0/0/0/NULL',
            ],
            'sky_freight' => [
                'id' => 'int/12/0/1/1/NULL',
                'name' => 'varchar/255/0/0/0/NULL',
                'region' => 'text/0/0/0/0/NULL',
                'money' => 'decimal/12/2/0/0/0',
                'nums' => 'int/12/0/0/0/NULL',
                'exceed' => 'decimal/12/2/0/0/0',
                'threshold' => 'decimal/12/2/0/0/0',
                'date' => 'datetime/0/0/0/0/NULL',
            ],
            'sky_withdrawal' => [
                'id' => 'int/12/0/1/1/NULL',
                'type' => 'varchar/255/0/0/0/NULL',
                'name' => 'varchar/255/0/0/0/NULL',
                'account_number' => 'varchar/255/0/0/0/NULL',
                'uid' => 'int/12/0/0/0/NULL',
                'remarks' => 'text/0/0/0/0/NULL',
                'state' => 'int/1/0/0/0/3',
                'result_code' => 'text/0/0/0/0/NULL',
                'money' => 'decimal/12/2/0/0/0',
                'endtime' => 'datetime/0/0/0/0/NULL',
                'addtime' => 'datetime/0/0/0/0/NULL',
            ],
            'sky_queue' => [
                'id' => 'int/22/0/1/1/NULL',
                'type' => 'int/22/0/0/0/2',
                'order' => 'varchar/255/0/0/0/NULL',
                'trade_no' => 'varchar/255/0/0/0/NULL',
                'uid' => 'int/25/0/0/0/NULL',
                'ip' => 'varchar/255/0/0/0/NULL',
                'input' => 'text/0/0/0/0/NULL',
                'num' => 'int/25/0/0/0/NULL',
                'gid' => 'int/25/0/0/0/NULL',
                'payment' => 'varchar/255/0/0/0/NULL',
                'price' => 'decimal/25/8/0/0/0',
                'remark' => 'text/0/0/0/0/NULL',
                'endtime' => 'datetime/0/0/0/0/NULL',
                'addtime' => 'datetime/0/0/0/0/NULL',
            ],
            'sky_cart' => [
                'id' => 'int/22/0/1/1/NULL',
                'uid' => 'int/22/0/0/0/-1',
                'cookie' => 'text/0/0/0/0/NULL',
                'ip' => 'varchar/255/0/0/0/NULL',
                'content' => 'text/0/0/0/0/NULL',
                'addtime' => 'datetime/0/0/0/0/NULL',
            ],
            'sky_mark' => [
                'id' => 'int/22/0/1/1/NULL',
                'gid' => 'int/25/0/0/0/NULL',
                'order' => 'varchar/255/0/0/0/NULL',
                'content' => 'text/0/0/0/0/NULL',
                'image' => 'text/0/0/0/0/NULL',
                'name' => 'text/0/0/0/0/NULL',
                'uid' => 'int/24/0/0/0/NULL',
                'seller' => 'varchar/255/0/0/0/NULL',
                'score' => 'varchar/255/0/0/0/NULL',
                'state' => 'int/2/0/0/0/3',
                'addtime' => 'datetime/0/0/0/0/NULL',
            ],
            'sky_tickets' => [
                'id' => 'int/22/0/1/1/NULL',
                'uid' => 'int/25/0/0/0/NULL',
                'order' => 'varchar/255/0/0/0/NULL',
                'name' => 'text/0/0/0/0/NULL',
                'content' => 'text/0/0/0/0/NULL',
                'message' => 'text/0/0/0/0/NULL',
                'state' => 'int/2/0/0/0/2',
                'type' => 'int/2/0/0/0/1',
                'grade' => 'int/25/0/0/0/NULL',
                'class' => 'text/0/0/0/0/NULL',
                'timetips' => 'varchar/255/0/0/0/NULL',
                'endtime' => 'datetime/0/0/0/0/NULL',
                'addtime' => 'datetime/0/0/0/0/NULL',
            ]
        ];
        return $array;
    }
}